#compdef overmask

autoload -U is-at-least

_overmask() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'-s+[Where original read-only data should be read from]:FILE:_files' \
'--seed-file=[Where original read-only data should be read from]:FILE:_files' \
'-o+[Where modified (written) data should be stored]:FILE:_files' \
'--overlay-file=[Where modified (written) data should be stored]:FILE:_files' \
'-m+[Where a mask of the modified data should be stored]:FILE:_files' \
'--mask-file=[Where a mask of the modified data should be stored]:FILE:_files' \
'-b+[Block size for all read and write operations]:BYTES:_default' \
'--block-size=[Block size for all read and write operations]:BYTES:_default' \
'-i[Ignore IO errors from the underlying files]' \
'--ignore-errors[Ignore IO errors from the underlying files]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_overmask_commands" \
"*::: :->overmask" \
&& ret=0
    case $state in
    (overmask)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:overmask-command-$line[1]:"
        case $line[1] in
            (apply)
_arguments "${_arguments_options[@]}" : \
'--force[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(a)
_arguments "${_arguments_options[@]}" : \
'--force[]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(clean)
_arguments "${_arguments_options[@]}" : \
'-t[Truncate the overlay and mask files to the last used byte]' \
'--truncate[Truncate the overlay and mask files to the last used byte]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(c)
_arguments "${_arguments_options[@]}" : \
'-t[Truncate the overlay and mask files to the last used byte]' \
'--truncate[Truncate the overlay and mask files to the last used byte]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(device)
_arguments "${_arguments_options[@]}" : \
'-n+[nbd device file (requires nbd kernel module)]:NBD_DEVICE:_files' \
'--nbd-device=[nbd device file (requires nbd kernel module)]:NBD_DEVICE:_files' \
'-t+[nbd device timeout in seconds]:SECONDS:_default' \
'--nbd-timeout=[nbd device timeout in seconds]:SECONDS:_default' \
'-p[Print every IO operation (\`read()\`, \`write()\`, \`flush()\`, etc)]' \
'--print-operations[Print every IO operation (\`read()\`, \`write()\`, \`flush()\`, etc)]' \
'-T[Don'\''t punch holes (fallocate) in overlay and mask on \`trim()\`]' \
'--trim-no-punch-holes[Don'\''t punch holes (fallocate) in overlay and mask on \`trim()\`]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(d)
_arguments "${_arguments_options[@]}" : \
'-n+[nbd device file (requires nbd kernel module)]:NBD_DEVICE:_files' \
'--nbd-device=[nbd device file (requires nbd kernel module)]:NBD_DEVICE:_files' \
'-t+[nbd device timeout in seconds]:SECONDS:_default' \
'--nbd-timeout=[nbd device timeout in seconds]:SECONDS:_default' \
'-p[Print every IO operation (\`read()\`, \`write()\`, \`flush()\`, etc)]' \
'--print-operations[Print every IO operation (\`read()\`, \`write()\`, \`flush()\`, etc)]' \
'-T[Don'\''t punch holes (fallocate) in overlay and mask on \`trim()\`]' \
'--trim-no-punch-holes[Don'\''t punch holes (fallocate) in overlay and mask on \`trim()\`]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(dev)
_arguments "${_arguments_options[@]}" : \
'-n+[nbd device file (requires nbd kernel module)]:NBD_DEVICE:_files' \
'--nbd-device=[nbd device file (requires nbd kernel module)]:NBD_DEVICE:_files' \
'-t+[nbd device timeout in seconds]:SECONDS:_default' \
'--nbd-timeout=[nbd device timeout in seconds]:SECONDS:_default' \
'-p[Print every IO operation (\`read()\`, \`write()\`, \`flush()\`, etc)]' \
'--print-operations[Print every IO operation (\`read()\`, \`write()\`, \`flush()\`, etc)]' \
'-T[Don'\''t punch holes (fallocate) in overlay and mask on \`trim()\`]' \
'--trim-no-punch-holes[Don'\''t punch holes (fallocate) in overlay and mask on \`trim()\`]' \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_overmask__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:overmask-help-command-$line[1]:"
        case $line[1] in
            (apply)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(clean)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(device)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_overmask_commands] )) ||
_overmask_commands() {
    local commands; commands=(
'apply:Apply the overlay on top of the seed using the mask' \
'a:Apply the overlay on top of the seed using the mask' \
'clean:Deduplicate data between the seed and overlay' \
'c:Deduplicate data between the seed and overlay' \
'device:Create a virtual block device to capture writes' \
'd:Create a virtual block device to capture writes' \
'dev:Create a virtual block device to capture writes' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'overmask commands' commands "$@"
}
(( $+functions[_overmask__subcmd__apply_commands] )) ||
_overmask__subcmd__apply_commands() {
    local commands; commands=()
    _describe -t commands 'overmask apply commands' commands "$@"
}
(( $+functions[_overmask__subcmd__clean_commands] )) ||
_overmask__subcmd__clean_commands() {
    local commands; commands=()
    _describe -t commands 'overmask clean commands' commands "$@"
}
(( $+functions[_overmask__subcmd__device_commands] )) ||
_overmask__subcmd__device_commands() {
    local commands; commands=()
    _describe -t commands 'overmask device commands' commands "$@"
}
(( $+functions[_overmask__subcmd__help_commands] )) ||
_overmask__subcmd__help_commands() {
    local commands; commands=(
'apply:Apply the overlay on top of the seed using the mask' \
'clean:Deduplicate data between the seed and overlay' \
'device:Create a virtual block device to capture writes' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'overmask help commands' commands "$@"
}
(( $+functions[_overmask__subcmd__help__subcmd__apply_commands] )) ||
_overmask__subcmd__help__subcmd__apply_commands() {
    local commands; commands=()
    _describe -t commands 'overmask help apply commands' commands "$@"
}
(( $+functions[_overmask__subcmd__help__subcmd__clean_commands] )) ||
_overmask__subcmd__help__subcmd__clean_commands() {
    local commands; commands=()
    _describe -t commands 'overmask help clean commands' commands "$@"
}
(( $+functions[_overmask__subcmd__help__subcmd__device_commands] )) ||
_overmask__subcmd__help__subcmd__device_commands() {
    local commands; commands=()
    _describe -t commands 'overmask help device commands' commands "$@"
}
(( $+functions[_overmask__subcmd__help__subcmd__help_commands] )) ||
_overmask__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'overmask help help commands' commands "$@"
}

if [ "$funcstack[1]" = "_overmask" ]; then
    _overmask "$@"
else
    compdef _overmask overmask
fi
